﻿@inherits BaseComponent

@if (Data.ContainsKey(Item.Id)) {
    if (Item.Type == FieldType.File) {
        var codes = new List<CodeInfo>();
        codes.Add(new CodeInfo("True", Language[Language.Have]));
        codes.Add(new CodeInfo("False", Language[Language.NotHave]));
        if (IsFilter) {
            <AntCheckboxGroup Codes="codes" Value="@Data[Item.Id].Values" ValueChanged="v=>OnSelectChangedAsync(Item.Id,v)" />
        } else {
            codes.Insert(0, new CodeInfo("", Language[Language.All]));
            <AntSelectCode Style="@SelectStyle" DataSource="codes" Value="@Data[Item.Id].Value" ValueChanged="v=>OnSelectChangedAsync(Item.Id,v)" />
        }
    } else if (Item.Type == FieldType.RadioList) {
        var codes = Cache.GetCodes(Item.Category, Language);
        if (IsFilter) {
            <AntCheckboxGroup Codes="codes" Value="@Data[Item.Id].Values" ValueChanged="v=>OnSelectChangedAsync(Item.Id,v)" />
        } else {
            <AntRadioGroup Codes="codes" Value="@Data[Item.Id].Value" ValueChanged="v=>OnSelectChangedAsync(Item.Id,v)" ButtonStyle="RadioButtonStyle.Solid" />
        }
    } else if (!string.IsNullOrWhiteSpace(Item.Category) || Item.Type == FieldType.Select) {
        if (IsFilter) {
            var codes = Cache.GetCodes(Item.Category, Language);
            <AntCheckboxGroup Codes="codes" Value="@Data[Item.Id].Values" ValueChanged="v=>OnSelectChangedAsync(Item.Id,v)" />
        } else {
            var codes = Cache.GetCodes(Item.Category, Language).ToCodes(Item.IsQueryAll ? Language[Language.All] : "");
            <AntSelectCode Style="@SelectStyle" DataSource="codes" Value="@Data[Item.Id].Value" ValueChanged="v=>OnSelectChangedAsync(Item.Id,v)" />
        }
    } else if (itemType.Contains("DateTime") || Item.Type == FieldType.Date || Item.Type == FieldType.DateTime) {
        <AntRangePicker @bind-RangeValue="@Data[Item.Id].Value" />
        @if (IsFilter) {
            <KButton Name="@Language.OK" OnClick="SearchDataAsync" />
        }
    } else if (itemType.Contains("Boolean") || Item.Type == FieldType.Switch || Item.Type == FieldType.CheckBox) {
        var codes = new List<CodeInfo>();
        codes.Add(new CodeInfo("True", Language[Language.Yes]));
        codes.Add(new CodeInfo("False", Language[Language.No]));
        if (IsFilter) {
            <AntCheckboxGroup Codes="codes" Value="@Data[Item.Id].Values" ValueChanged="v=>OnSelectChangedAsync(Item.Id,v)" />
        } else {
            codes.Insert(0, new CodeInfo("", Language[Language.All]));
            <AntSelectCode Style="@SelectStyle" DataSource="codes" Value="@Data[Item.Id].Value" ValueChanged="v=>OnSelectChangedAsync(Item.Id,v)" />
        }
    } else {
        <AntInput Style="@InputStyle" Value="@Data[Item.Id].Value" ValueChanged="v=>Data[Item.Id].Value=v" OnEnter="SearchDataAsync" Placeholder="@Language[Language.QueryByEnter]" />
    }
}